﻿@using LdCms.EF.DbModels
@using LdCms.Common.Extension
@using LdCms.Common.Utility
@model IEnumerable<Ld_Sys_Function>
@{
    ViewData["Title"] = "List";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 权限管理 <a id="btn_refresh" class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c">
        功能名称：<input type="text" class="input-text" style="width:350px" placeholder="输入功能节点编号" id="keyword" name="keyword" value="@ViewBag.keyword" />
        <button type="submit" class="btn btn-success radius" id="search" name="search" onclick="$.mainu.search()"><i class="Hui-iconfont">&#xe665;</i> 查找</button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:;" onclick="$.mainu.deleteBatch()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
            <a href="@Url.Action("list")" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe667;</i> 权限列表</a>
            <a href="javascript:;" onclick="$.mainu.add('添加权限节点', '@Url.Action("add")', '', '')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加权限节点</a>
        </span>
        <span class="r">共有数据：<strong>@ViewBag.Count</strong> 条</span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-hover table-bg table-sort">
            <thead>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th width="100">功能编号</th>
                    <th width="">功能名称</th>
                    <th width="100">上级编号</th>
                    <th width="70">级别</th>
                    <th width="70">状态</th>
                    <th width="120">操作时间</th>
                    <th width="120">操作</th>
                </tr>
            </thead>
            <tbody>
                @if (Model != null)
                {
                    foreach (var m in Model)
                    {
                        <tr class="text-c">
                            <td><input type="checkbox" name="id" value="@m.FunctionID"></td>
                            <td>@m.FunctionID</td>
                            <td class="text-l">@(Utility.StringRepeat("　", m.RankID.ToInt()-1)) @(m.RankID.ToInt() > 1 ? "" : "")@m.FunctionName</td>
                            <td>@m.ParentID</td>
                            <td>@m.RankID</td>
                            <td class="td-status">@(m.State.ToBool()? Html.Raw("<span class='label label-success radius'>已启用</span>") : Html.Raw("<span class='label label-defaunt radius'>已停用</span>"))</td>
                            <td>@(m.CreateDate.HasValue ? m.CreateDate.Value.ToString("yyyy-MM-dd HH:mm") : "-")</td>
                            <td class="td-manage">
                                @if (m.State.ToBool())
                                {
                                    <a style="text-decoration:none" onClick="$.mainu.stop(this,'@m.FunctionID')" href="javascript:;" title="停用">停用</a>
                                }
                                else
                                {
                                    <a style="text-decoration:none" onClick="$.mainu.start(this,'@m.FunctionID')" href="javascript:;" title="启用">启用</a>
                                }
                                <a href="javascript:;" onclick="$.mainu.edit('编辑权限节点','@Url.Action("edit", new { functionid = m.FunctionID })','@m.FunctionID','','')" class="ml-5" style="text-decoration:none" title="编辑">编辑</a>
                                <a href="javascript:;" onclick="$.mainu.delete(this,'@m.FunctionID')" class="ml-5" style="text-decoration:none" title="删除">删除</a>
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>
    </div>
</div>
<div class="pt-30" style="width:100%; height:60px;"></div>
@*
    --------------
    页面底部JS脚本
    --------------
*@
@section scripts{
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="~/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript" src="~/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="~/admin/lib/laypage/1.2/laypage.js"></script>
    <script type="text/javascript">
        (function ($) {
            $.mainu = {
                init: function () {
                    $('.table-sort').dataTable({
                        "lengthMenu": false,                            //显示数量选择
                        "bFilter": false,                               //过滤功能
                        "bPaginate": false,                             //翻页信息
                        "bInfo": false,                                 //数量信息
                        "aaSorting": [[1, "asc"]],                      //默认第几个排序
                        "bStateSave": true,                             //状态保存
                        "aoColumnDefs": [
                          { "orderable": false, "aTargets": [0, 7] }    // 制定列不参与排序
                        ],
                        "aLengthMenu": [5, 10, 25, 50, 100]
                    });
                },
                add: function (title,url,w,h) {
                    layer_show(title, url, w, h);
                },
                edit: function (title, url, id, w, h) {
                    layer_show(title, url, w, h);
                },
                search: function () {
                    $keyword = $("input[name='keyword']").val();
                    if ($keyword == "") {
                        layer.alert('请输入功能节点编号', { icon: 5 });
                        return;
                    }
                    var url = "?keyword=" + $keyword + "";
                    window.location.href = url;
                },
                stop: function (obj, id) {
                    layer.confirm('确认要停用吗？', function (index) {
                        $.ajax({
                            type: 'POST',
                            url: '@Url.Action("UpdateState")',
                            data: { functionId: id, state: false },
                            dataType: 'json',
                            success: function (result) {
                                var state = result.state;            //错误代码
                                var message = result.message;        //错误说明
                                if (state == "success") {
                                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="$.mainu.start(this,\'' + id + '\')" href="javascript:;" title="启用">启用</a>');
                                    $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
                                    $(obj).remove();
                                    layer.msg('已停用!', { icon: 5, time: 3000 });
                                } else {
                                    layer.msg(message, { icon: 5, time: 3000 });
                                }
                            },
                            error: function (data) {
                                console.log(data.msg);
                            }
                        });
                    });
                },
                start: function (obj, id) {
                    layer.confirm('确认要启用吗？', function (index) {
                        $.ajax({
                            type: 'POST',
                            url: '@Url.Action("UpdateState")',
                            data: { functionId: id, state: true },
                            dataType: 'json',
                            success: function (result) {
                                var state = result.state;          //错误代码
                                var message = result.message;        //错误说明
                                if (state == "success") {
                                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="$.mainu.stop(this,\'' + id + '\')" href="javascript:;" title="停用">停用</a>');
                                    $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
                                    $(obj).remove();
                                    layer.msg('已启用!', { icon: 6, time: 3000 });
                                } else {
                                    layer.msg(message, { icon: 5, time: 3000 });
                                }
                            },
                            error: function (data) {
                                console.log(data.msg);
                            }
                        });
                    });
                },
                delete: function (obj, id) {
                    layer.confirm('确认要删除吗？', function (index) {
                        $.ajax({
                            type: 'POST',
                            url: '@Url.Action("Delete")',
                            data: { functionId: id },
                            dataType: 'json',
                            success: function (result) {
                                var state = result.state;
                                var message = result.message;
                                if (state == "success") {
                                    $(obj).parents("tr").remove();
                                    layer.msg('已删除!', { icon: 1, time: 3000 });
                                } else {
                                    layer.msg(message, { icon: 5, time: 3000 });
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                if (XMLHttpRequest.status != 200) {
                                    layer.alert("系统错误！", { icon: 5 });
                                }
                            }
                        });
                    });
                },
                deleteBatch: function () {
                    layer.confirm('确认要删除吗？', function (index) {
                        var arrId = [];
                        $("input:checkbox[name='id']:checked").each(function () {
                            //alert($(this).val());
                            arrId.push($(this).val());
                        });
                        if (arrId.length == 0) {
                            layer.msg('请选择需要删除日志！', { icon: 5, time: 2000 });
                            return;
                        }
                        $.ajax({
                            type: 'POST',
                            url: '@Url.Action("DeleteBatch")',
                            data: { arrFunctionId: arrId },
                            dataType: 'json',
                            success: function (result) {
                                var state = result.state;          //错误代码
                                var message = result.message;        //错误说明
                                if (state == "success") {
                                    window.location.replace(location.href);
                                } else {
                                    layer.msg(message, { icon: 5, time: 1000 });
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                if (XMLHttpRequest.status != 200) {
                                    layer.alert("系统错误！", { icon: 5 });
                                }
                            }
                        });
                    });
                }
            };
            $(function () {
                $.mainu.init();
            });
        })(jQuery);
    </script>
}

